package com.jpcc.vw.onlineRadio.http;

import android.os.Build;

import com.orhanobut.logger.Logger;

import java.io.IOException;

import okhttp3.Interceptor;
import okhttp3.MediaType;
import okhttp3.Request;
import okhttp3.Response;
import okhttp3.ResponseBody;

/**
 * Created by hzwangchenyan on 2017/3/30.
 */
public class HttpInterceptor implements Interceptor {
    private static final String UA = "User-Agent";

    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request()
                .newBuilder()
                .addHeader(UA, makeUA())
                .build();

        Response originalResponse = chain.proceed(request);
        String body = originalResponse.body().string();
        Logger.i("httpinter-->"+request.toString());
        Logger.i("httpClient Response-->"+body);
        return originalResponse.newBuilder()
                .body(ResponseBody.create(MediaType.parse("UTF-8"), body))
                .build();
//        return chain.proceed(request);
    }

    private String makeUA() {
        return Build.BRAND + "/" + Build.MODEL + "/" + Build.VERSION.RELEASE;
    }
}
